package se.teamscape.client.presenter;

import net.customware.gwt.presenter.client.EventBus;
import se.teamscape.client.event.LoginRequestEvent;
import se.teamscape.client.event.LoginRequestEventHandler;

import com.google.gwt.user.client.Window;
import com.google.inject.Inject;

/**
 * LoginPresenter handles user logins.
 * 
 * A user login request ends up in a LoginRequestEvent, which we register as a
 * handler for.
 * 
 * @author Andreas Borglin
 * 
 */
public class LoginPresenter extends BasePresenter<LoginPresenter.Display> implements LoginRequestEventHandler {

    public interface Display extends BasePresenter.Display {

        String getUsername();

        String getPassword();

    }

    @Inject
    public LoginPresenter(Display display, EventBus eventBus) {
        super(display, eventBus);

        eventBus.addHandler(LoginRequestEvent.TYPE, this);
    }

    @Override
    protected void onLazyBind() {
    }

    @Override
    protected void onRevealDisplay() {

    }

    @Override
    public void onLoginRequest(LoginRequestEvent event) {

        Window.alert("Login request for user: " + event.getUsername());
        // TODO: Validate input and send to server if OK

    }

}
